package com.lyy.photovoltaic.controller;

import com.lyy.photovoltaic.beans.Equipments;
import com.lyy.photovoltaic.beans.Users;
import com.lyy.photovoltaic.common.vo.ResultVO;
import com.lyy.photovoltaic.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/user")
@Api(value = "提供用户的登录和注册接口", tags = "用户管理")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户登录接口")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "uid", value = "用户登录账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "用户登录密码", required = true)
    })
    @PostMapping("/login")
    public ResultVO login(@RequestParam("uid") String uId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = userService.checkLogin(uId, pwd);

        return resultVO;
    }

    @PostMapping("/regist")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "uid", value = "用户注册账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "pwd", value = "用户注册密码", required = true)
    })
    @ApiOperation(value = "用户注册接口")
    public ResultVO register(@RequestParam("uid") String uId, @RequestParam("pwd") String pwd) {
        ResultVO resultVO = userService.userRegist(uId, pwd);
//        System.out.println("注册成功");
        return resultVO;
    }
    @PostMapping("/updatePwd")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "uid", value = "用户注册账号", required = true),
            @ApiImplicitParam(dataType = "string", name = "oPwd", value = "用户原密码", required = true),
            @ApiImplicitParam(dataType = "string", name = "nPwd", value = "用户新密码", required = true)

    })
    @ApiOperation(value = "用户修改密码接口")
    public ResultVO updatePassword(@RequestParam("uid") String uId, @RequestParam("oPwd") String originPwd,
                                   @RequestParam("nPwd") String newPwd) {

        ResultVO resultVO = userService.updatePassword(uId, originPwd, newPwd);
//        System.out.println("注册成功");
        return resultVO;
    }

}
